<?php

	require_once("includes/config.php");
	require_once("includes/functions.php");
	require_once("classes/class.Team.php");
	require_once("classes/class.Field.php");
	require_once("classes/class.User.php");
	require_once("classes/class.Metric.php");
	
	global $db_host, $db_username, $db_password, $db_database;

	$obj_user = new User();
	$obj_user->Load($login_username);


?>
	
		<form id="form_metric" name="form_metric" method="post" action="process.php">
		
		<input id="form_id" name="form_id" type="hidden" value="metric" />
		<input id="team_name" name="team_name" type="hidden" value="<?=$param_team_name;?>" />
		<input id="user_id" name="user_id" type="hidden" value="<?=$login_username;?>" />
		
		<div style="height:10px;">&nbsp;</div>
		
		<div class="heading_page">
			<?=$app_name." ".$app_version;?>
		</div>
		<div class="heading_page_sub">
			New Metrics Entry
		</div>
		
		<table style="width:10O%;" cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td class="detail_label">Name:</td>
				<td class="detail_value">
					<?=$obj_user->GetName();?>
				</td>
			</tr>
			<tr>
				<td class="detail_label">Date:</td>
				<td class="detail_value">
					<!--<?=date("l jS F Y",make_date($param_datestamp));?>-->
					<!--<input type="text" id="datestamp" name="datestamp" class="general" maxlength="10" size="10" />-->
					<select id="datestamp" name="datestamp" class="control">
						<? echo make_datepicker(); ?>
					</select>
				</td>
			</tr>		
		</table>

		<br/>
		<table style="width:10O%;" cellpadding="0" cellspacing="0" border="0">

			<tr>
				<td class="field_label" colspan="2" style="background-color:#000066;color:#ffffff;height:40px;vertical-align:top;">
					<p id="field_help" name="field_help"></p>			
				</td>
			</tr>
	
		<?
	
			mysql_connect($db_host,$db_username,$db_password);
			@mysql_select_db($db_database) or die("Unable to select database");
			//$db_query = "SELECT * FROM field WHERE team_name = '$param_team_name' ORDER BY field_order ASC;";
			$db_query = "SELECT * FROM field ORDER BY team_name, field_order ASC;";
			$db_result = mysql_query($db_query);
			$db_count = mysql_num_rows($db_result);
			mysql_close();	
			
			$i=0;
			while ($i < $db_count) {
		
				$field_name	= mysql_result($db_result,$i,"field_name");
				$team_name = mysql_result($db_result,$i,"team_name");
				$obj_team = new Team();
				$obj_team->Load($team_name);
				$team_description = $obj_team->GetDescription();
				$obj_team = null;
				$obj_field = new Field();
				$obj_field->Load($field_name);

				if($obj_field->GetType()=="NUMBER") {
					$control_default = "0";
					$control_width = "10";
					$control_max_length = "10";
				}

				if($obj_field->GetType()=="TEXT") {
					$control_default = "";
					$control_width = "30";
					$control_max_length = "255";					
				}

				if($obj_field->GetType()=="DATE") {
					$control_default = "DD/MM/YYYY";
					$control_width = "12";
					$control_max_length = "10";					
				}

				if($i%2==0) {
					$row_css = "background-color:#ffffff;";
				} else {
					$row_css = "background-color:#eeeeff;";			
				}

				if($team_current!=$team_name and $obj_user->IsInTeam($obj_field->GetTeamName())) {
				
			?>
			
				<tr>
					<td class="field_label" colspan="2" style="background-color:#000033;color:#ffffff;height:20px;vertical-align:top;">
						<p style="font-size:11pt;"><?=$team_name?></p>			
					</td>
				</tr>	
				
			<?	
					
				}

				if($obj_user->IsInTeam($obj_field->GetTeamName())) {

			?>
				<tr>
					<td class="field_label" style="<?=$row_css?>" onmouseover="set_field_help('<?=$obj_field->GetHelp()?>');" onmouseout="set_field_help('');">
						<?=$obj_field->GetDescription()?>
					</td>				
					<td class="field_value" style="<?=$row_css?>" onmouseover="set_field_help('<?=$obj_field->GetHelp()?>');" onmouseout="set_field_help('');">
						<input id="FIELD_<?=$obj_field->GetName()?>" name="FIELD_<?=$obj_field->GetName()?>" class="control" type="text" maxlength="<?=$control_max_length;?>" size="<?=$control_width;?>" value="<?=$control_default;?>" title="<?echo "FIELD_".$obj_field->GetName()?>" />	
						<input id="TEAM_<?=$obj_field->GetName()?>" name="TEAM_<?=$obj_field->GetName()?>" type="hidden" value="<?=$obj_field->GetTeamName();?>" />
					</td>
				</tr>

			<?
	
				}
				
				$team_current = $team_name;
				
				$i++;
			
			}

		?>


		
			<tr>
				<td colspan="2" class="field_label">
					<input type="submit" name="Submit" value="Save Entry" class="button" onmouseover="set_field_help('Save the current metrics entry');" onmouseout="set_field_help('');"/>			
					<input type="button" name="Cancel" value="Cancel" class="button" onmouseover="set_field_help('Cancel the current metrics entry');" onmouseout="set_field_help('');" onclick="location.href='index.php?page=default'"/>			
				</td>
			</tr>
		
		</table>
		
 	</form>

